package weather.language.forecast;

import java.util.HashSet;
import java.util.Set;

import weather.dictionary.ConditionsGroupsAnswersDictionary;

/**
 * Contains necessary informations for preparing an answer to user
 * @author Marian Szczykulski
 *
 */
public class WeatherAnswer 
{
	private Set<ConditionsGroup> 	group		=	null;
	private Condition			condition	=	null;
	private String 				highTemperature	= null;
	private String 				lowTemperature	= null;
	private String 				avgTemperature	= null;
	
	public String toString()
	{
		return null;	
	}
	public String toStringCondition()
	{
		if(group!=null && condition!=null)
			return condition.toString();
		else
			return null;
	}
	
	public String toStringHighTemperature()
	{
		if(highTemperature==null)
			return null;
		else
			return "high temperature will be "+highTemperature+" of celsius";
	}
	
	public String toStringLowTemperature()
	{
		if(lowTemperature==null)
			return null;
		else
			return "low temperature will be "+lowTemperature+" of celsius";
	}
	
	public String toStringMidTemperature()
	{
		if(avgTemperature!=null)
		{
			return "medium temperature will be "+avgTemperature+" of celsius";
		}
		else
			return null;
	}
	/**
	 * Checks if an answer is appropriate - valid for specified group
	 * @return true if answer is correct
	 */
	public boolean isAnswerCorrect()
	{	
		if(group==null)
			return true;
		else
		{
			for(ConditionsGroup gr : group)
			{
				if(gr.containsCondition(condition))
					return true;
			}
			return false;
		}
	}
	
	
	public Set<ConditionsGroup> getGroup() {
		return group;
	}
	public String groupsToString()
	{
		String ret = "";
		String separator = "";
		ConditionsGroupsAnswersDictionary cgad = ConditionsGroupsAnswersDictionary.instance();
		int iter = 1;
		int size = group.size();
		for(ConditionsGroup cg : group)
		{
			ret += separator + cgad.getValue(cg.getId());
			if(iter==size-1)
				separator = " and ";
			else
				separator = ", ";
			iter++;
		}
		
		return ret;
	}
	
	public void setGroup(Set<ConditionsGroup> group) {
		this.group = group;
	}
	public void addGroup(ConditionsGroup group) {
		if(this.group == null)
			this.group = new HashSet<ConditionsGroup>();
		this.group.add(group);
	}
	public Condition getCondition() {
		return condition;
	}
	public void setCondition(Condition condition) {
		this.condition = condition;
	}

	public String getHighTemperature() {
		return highTemperature;
	}

	public void setHighTemperature(String highTemperature) {
		this.highTemperature = highTemperature;
	}

	public String getLowTemperature() {
		return lowTemperature;
	}

	public void setLowTemperature(String lowTemperature) {
		this.lowTemperature = lowTemperature;
	}
	public String getAvgTemperature() {
		return avgTemperature;
	}
	public void setAvgTemperature(String avgTemperature) {
		this.avgTemperature = avgTemperature;
	}
	
	
}
